

import { getUser, searchUserData } from '@/services/ant-design-pro/api';
import { Effect, Reducer } from 'umi';

export interface UserModelState {
  UserItem:IUserItem[],
  tol:number
}

export interface UserModelType {
  namespace: 'user';
  state: UserModelState;
  effects: {
    searchUser:Effect
    getuserList: Effect;
  };
  reducers: {
    save: Reducer<UserModelState>;
  };

}

const PageModel: UserModelType = {
  namespace: 'user',
  state: {
    UserItem: [],
    tol:0
  },
  //副作用
  effects: {
    *getuserList({ payload }, { call, put }) {
      const result = yield call(getUser,payload)
      if (result.data) {
        yield put({
          type: 'save',
          payload: {
            UserItem: result.data[0],
            tol:result.data[1]
          }
        })
      }
    },
    *searchUser({payload},{call,put}){
       const result =yield call(searchUserData,payload)
       console.log(result);
       
    }
  },
  //同步修改state的操作
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },

  },

};

export default PageModel;